﻿using DailyApp.WPF.DTOs;
using DailyApp.WPF.Service;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace DailyApp.WPF.ViewModels.DialogViewModels
{
    /// <summary>
    /// 添加对话框的视图模型
    /// </summary>
    internal class AddWaitUCViewModel : BindableBase, IDialogHostAware
    {
        //属性
        public WaitTodoInfoDTO WaitTodoInfoDTO { get; set; }//单向绑定即可


        //委托命令
        public DelegateCommand SaveCommand { get; set; }
        public DelegateCommand CancelCommand { get; set; }



        public AddWaitUCViewModel()
        {

        }

        public void OnDialogOpening(IDialogParameters parameters)
        {
            CancelCommand = new DelegateCommand(CancelFuc);
            SaveCommand = new DelegateCommand(SaveFunc);
            WaitTodoInfoDTO = new WaitTodoInfoDTO();
        }

        /// <summary>
        /// 保存信息并回传
        /// </summary>
        private void SaveFunc()
        {
            if (WaitTodoInfoDTO.Title == null || WaitTodoInfoDTO.Content == null || WaitTodoInfoDTO.Status == null)
            {
                MessageBox.Show("请完全输入内容！");
                return;
            }

            if (DialogHost.IsDialogOpen("RootDialog"))
            {
                DialogParameters param = new DialogParameters
                {
                    {"AddWaitInfo",WaitTodoInfoDTO }
                };

                DialogHost.Close("RootDialog", new DialogResult(ButtonResult.OK, param));//回传数据
            }
        }


        /// <summary>
        /// 取消添加事项弹窗
        /// </summary>
        private void CancelFuc()
        {
            //整个 DialogHost 系统采用 容器托管模式。当你在主界面定义 Identifier="RootDialog" 时，实际上创建了一个全局对话框容器，所有在该容器内打开的对话框都共享这个宿主。
            //判断xx容器当前是否正在显示对话框层
            if (DialogHost.IsDialogOpen("RootDialog"))
            {
                DialogHost.Close("RootDialog", new DialogResult(ButtonResult.No));
            };
        }
    }
}
